package com.quanyan.stadium.biz.impl;

import com.quanyan.common.Plugin.Page;
import com.quanyan.stadium.biz.BizUserGameScheduleDao;
import com.quanyan.stadium.entity.TbUserGameSchedule;
import com.quanyan.stadium.entity.TbUserGameScheduleExample;
import com.quanyan.stadium.mapper.TbUserGameScheduleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by lei.w on 2016/7/9.
 */
@Service
public class BizUserGameScheduleDaoImpl implements BizUserGameScheduleDao {

    @Autowired
    TbUserGameScheduleMapper tbUserGameScheduleMapper;

    @Override
    public List<TbUserGameSchedule> selectUserGameScheduleByUidAndStatus(Integer uid, Integer status, Integer pageNum, Integer pageSize) {
        TbUserGameScheduleExample example = new TbUserGameScheduleExample();
        TbUserGameScheduleExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(uid);
        criteria.andScheduleStatusEqualTo(status.byteValue());
        example.setPage(new Page(pageSize * (pageNum), pageSize));

        return tbUserGameScheduleMapper.selectByExample(example);
    }

    @Override
    public List<TbUserGameSchedule> selectUserGameScheduleByUidAndStatus(Integer uid, Integer status) {
        TbUserGameScheduleExample example = new TbUserGameScheduleExample();
        TbUserGameScheduleExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(uid);
        criteria.andScheduleStatusEqualTo(status.byteValue());
        // 默认查询三个月内数
        criteria.andStartTimeGreaterThan(new Date(System.currentTimeMillis() - 7776000000L));
        return tbUserGameScheduleMapper.selectByExample(example);
    }

    @Override
    public Integer countUserGameScheduleByUidAndStatus(Integer uid, Integer status) {
        TbUserGameScheduleExample example = new TbUserGameScheduleExample();
        TbUserGameScheduleExample.Criteria criteria = example.createCriteria();
        criteria.andUidEqualTo(uid);
        criteria.andScheduleStatusEqualTo(status.byteValue());

        return tbUserGameScheduleMapper.countByExample(example);
    }


}
